/* indent size: 1 */

module.exports = app => {
	const DataTypes = app.Sequelize;

	const Model = app.model.define('auth_user', {
		id: {
			type: DataTypes.INTEGER(11),
			allowNull: false,
			primaryKey: true,
			autoIncrement: true
		},
		
		username: {
			type: DataTypes.STRING(30),
			allowNull: true
		},
		email: {
			type: DataTypes.STRING(50),
			allowNull: true
		},
		password: {
			type: DataTypes.STRING(100),
			allowNull: true
		},
		createdAt: {
			type: DataTypes.DATE,
			allowNull: true
		},
		updatedAt: {
			type: DataTypes.DATE,
			allowNull: true
		},
        type: {
            type: DataTypes.INTEGER(2).UNSIGNED,
            allowNull: true,
            defaultValue: 0,
            comment: '店铺状态，0-> 系统用户，1-> 商家'
		},
		is_delete: {
			type: DataTypes.INTEGER(1).UNSIGNED,
			allowNull: false,
			defaultValue: '0',
			comment: '是否删除，0->存在，1->删除'
		},
	}, {
		tableName: 'auth_user',
		timestamps: false
	});
	
	Model.sync({ alter: true });

	Model.associate = function() {
		app.model.AuthUser.belongsToMany(app.model.AuthGroup, {
			through: app.model.AuthUserGroup,
			foreignKey: 'user_id',
			otherKey: 'group_id'
		});
		app.model.AuthUser.belongsToMany(app.model.Shop, {
			through: app.model.AuthUserShop,
			foreignKey: 'user_id',
			otherKey: 'shop_id'
		});
	}

	return Model;
};
